<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c"%>
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui"%>
<%@ taglib uri="/WEB-INF/tld/sys.tld" prefix="sys"%>
<%@ taglib uri="/WEB-INF/tld/fmt.tld" prefix="fmt"%>
<%
    String path = request.getContextPath();
%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>${tabTitle}</title>
<jsp:include page="../../import.jsp" flush="true" />
</head>
<body class="iframeBody">
	<div class="Wrapper">
		<div>
			<div id="pageInTab" class="pageInTab">
				<form id="ins_cfg_info_edit_form">
					<div class="fieldset1 tabel_col clearFix">
						<div class="fieldBox col_33">
							<div class="label">机构名称</div>
							<div class="field">
								<span name="fundRasInsNm" id="fundRasInsNm">${fundRasInsNm}</span>
							</div>
						</div>
						<div class="fieldBox col_33">
							<div class="label">客户名称</div>
							<div class="field">
								<span >${cstNm}</span>
							</div>
						</div>
						<div class="fieldBox col_33">
							<div class="label">身份证号码</div>
							<div class="field">
								<span >${certNo}</span>
							</div>
						</div>

						<div class="fieldBox col_33">
							<div class="label">开户银行</div>
							<div class="field">
                                <select name="bkCd" id="bkCd" value="${bkCd}" validate="{required:true}">
	                                <c:if test="${bkCd == null || bkCd == ''}">
	                                	<option value="" selected="selected">--请选择--</option>
	                                </c:if>
	                                <c:if test="${bkCd != null && bkCd != ''}">
	                                	<option value="">--请选择--</option>
	                                </c:if>
                                    <c:forEach items="${bankList}" var="item">
                                    	<c:if test="${item.key == bkCd}">
                                        	<option value="${item.key}" selected="selected">${item.value}</option>
                                    	</c:if>
                                    	<c:if test="${item.key != bkCd}">
                                        	<option value="${item.key}">${item.value}</option>
                                    	</c:if>
                                    </c:forEach>
                                </select>
								<span class="requiredSymbol">*</span>
								<span class="requiredSymbol">单笔限额：<span class="requiredSymbol" id="singleQuota">${singleQuota}</span></span>
							</div>
						</div>
						<div class="fieldBox col_33">
							<div class="label">银行账号</div>
							<div class="field">
								<input name="accNo" id="accNo" type="text" class="ui-textbox" value="${accNo}" validate="{number:true, maxlength:22, minlength:15}">
								<span class="requiredSymbol">*</span>
							</div>
						</div>
						<div class="fieldBox col_33">
							<div class="label">预留手机号</div>
							<div class="field">
								<input name="mp" id="mp" type="text" class="ui-textbox" value="${mp}" validate="{number:true, maxlength:11, minlength:11}">
								<span class="requiredSymbol">*</span>
							</div>
						</div>
						<div class="fieldBox col_33">
							<div class="label">绑卡验证码</div>
							<div class="field">
								<input name="phoneCode" id="phoneCode" type="text" class="ui-textbox" value="">
								<span class="requiredSymbol">*</span>
								<sys:FlowFrmAth preTaskIds="${preTaskIds}" athCd="addPrjBscInfo" pInstId="${pInstId}">
									<span id="msmCodeCfg" class="sq-button sq-button-round" onclick="return msmCode();">获取</span>
								</sys:FlowFrmAth>
							</div>
						</div>
						<div class="fieldBox col_33">
							<div class="label">身份证有效期(止)</div>
							<div class="field">
								<input name="certValidEDt" id="certValidEDt" type="text" class="ui-datepicker"
									   <c:if test="${certValidEDt != '长期'}">value="${certValidEDt}"</c:if>>
								<div><input type="checkbox" name="certValidEDtAll" id="certValidEDtAll" value="长期" onchange="enduring(this)"
											<c:if test="${certValidEDt == '长期'}">checked</c:if><c:if test="${certValidEDt=='2099-12-31'}">checked</c:if>>长期</div>
								<span class="requiredSymbol">*</span>
							</div>
						</div>
						<div class="fieldBox col_50">
							<div class="label">民族</div>
							<div class="field">
								<select name="nation" id="nation" value="${nation}" >
									<c:if test="${nation == null || nation == ''}">
										<option value="" selected="selected">--请选择--</option>
									</c:if>
									<c:if test="${nation != null && nation != ''}">
										<option value="">--请选择--</option>
									</c:if>
									<c:forEach items="${nationList}" var="item">
										<c:if test="${item.value == nation}">
											<option value="${item.value}" selected="selected">${item.value}</option>
										</c:if>
										<c:if test="${item.value != nation}">
											<option value="${item.value}">${item.value}</option>
										</c:if>
									</c:forEach>
								</select>
								<span class="requiredSymbol">*</span>
							</div>
						</div>
						<div class="fieldBox col_50">
							<div class="label">月收入(元)</div>
							<div class="field">
								<input name="monthInc" id="monthInc" type="text" class="ui-textbox" value="<fmt:formatNumber type="number" value="${monthInc}"  pattern=".00"/>" validate="{number:true}">
								<span class="requiredSymbol">*</span>
							</div>
						</div>
						<div class="fieldBox col_50">
							<div class="label">居住省市</div>
							<div class="field">
								<jsp:include page="../../system/sysRegion/regionSecUse.jsp" flush="true">
									<jsp:param name="regionSecUseShowLvl" value="2"/>
								</jsp:include>
								<span class="requiredSymbol">*</span>
							</div>
						</div>
						<div class="fieldBox col_50">
							<div class="label">居住地址详情</div>
							<div class="field">
								<input name="postAddr" id="postAddr" type="text" class="ui-textbox" value="${postAddr}" validate="{required:true}">
								<span class="requiredSymbol">*</span>
							</div>
						</div>
						<div class="fieldBox col_50">
							<div class="label">户籍省市</div>
							<div class="field">
								<jsp:include page="../../system/sysRegion/region.jsp" flush="true">
									<jsp:param name="regionShowLvl" value="3"/>
								</jsp:include>
								<span class="requiredSymbol">*</span>
							</div>
						</div>
						<div class="fieldBox col_100">
							<div class="label">兴邦抵押合同模板</div>
							<div class="field">
								<span class="btns"><span class="sq-button sq-button-round" onclick="downloadFileByUrl();">打包下载</span></span>
								&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
								<span style="color: #20099b">友情提示：资方审核通过后，从兴邦抵押合同模板处下载附件进行签订。</span>
							</div>
						</div>
						<!-- hide data -->
						<div class="fieldBox col_100" style="display: none;">
							<div class="field">
								<input name="prjId" id="prjId" type="text" class="ui-textbox" value="${prjId}">
								<input name="cstId" id="cstId" type="text" class="ui-textbox" value="${cstId}">
								<input name="cstNm" id="cstNm" type="text" class="ui-textbox" value="${cstNm}">
								<input name="certNo" id="certNo" type="text" class="ui-textbox" value="${certNo}">
								<input name="cstAccInfoId" id="cstAccInfoId" type="text" class="ui-textbox" value="${cstAccInfoId}">
								<input name="fundRasInsId" id=fundRasInsId type="text" class="ui-textbox" value="${fundRasInsId}">
							</div>
						</div>
					</div>
	                <div id="saveInsCfgDiv" class="btnsBox">
	                    <sys:FlowFrmAth preTaskIds="${preTaskIds}" athCd="addPrjBscInfo" pInstId="${pInstId}">
	                        <span id="saveInsCfg" class="sq-button sq-button-round" onclick="return saveInfo();">保存</span>
	                    </sys:FlowFrmAth>
                	</div>
				</form>
			</div>
		</div>
	</div>

<script type="text/javascript">

var detailFlag = '${detailFlag}';
var updateFlag = '${updateFlag}';
var singleQuotaMap = '${singleQuotaMap}'; //
var isNeedPhoneCode = 1;
// REQ-7008 信审初审节点 客户经理 可修改字段
var fromCAFlag = '${fromCAFlag}';
var fromCMFlag = '${fromCMFlag}';

$(function () {
	initData();

	$("#bkCd").change(function(){
		var bankNo = $("#bkCd").val();
		var singleQuota = singleQuotaMap[bankNo+""];
		$("#singleQuota").html(singleQuota ? singleQuota : "");
	});
});

function initData() {
    $("#ins_cfg_info_edit_form").ligerForm({
        validate: true
    });
	
	disabledInput();
    disabledInput2();
	enableFields();

    if(singleQuotaMap!=""){
		singleQuotaMap = eval("("+singleQuotaMap+")");
	}
	//设置省、市
	setRgnProvCdUpdataValue('${domicileProvince}');
	setRgnCityCdUpdataValue('${domicileCity}');
	setRgnProvCdSecUseUpdataValue('${postProvince}');
	setRgnCityCdSecUseUpdataValue('${postCity}');
	enduring();
}

function disabledInput() {
	if(detailFlag == "true") {
		liger.get("bkCd").setDisabled();
		liger.get("accNo").setDisabled();
		liger.get("mp").setDisabled();
		liger.get("certNo").setDisabled();
		liger.get("phoneCode").setDisabled();
		liger.get("certValidEDt").setDisabled();
		liger.get("certValidEDtAll").setDisabled();
		liger.get("rgnProvCdSecUse").setDisabled();
		liger.get("rgnCityCdSecUse").setDisabled();
		liger.get("postAddr").setDisabled();
		liger.get("rgnProvCd").setDisabled();
		liger.get("rgnCityCd").setDisabled();
		liger.get("nation").setDisabled();
		liger.get("monthInc").setDisabled();

		$("#msmCodeCfg").hide();
		$("#saveInsCfgDiv").hide();
	}
}


function disabledInput2() {
    if(updateFlag == "true") {
        liger.get("bkCd").setDisabled();
        liger.get("accNo").setDisabled();
        liger.get("mp").setDisabled();
        liger.get("cstNm").setDisabled();
		liger.get("certValidEDt").setDisabled();
		liger.get("certValidEDtAll").setDisabled();
		liger.get("rgnProvCdSecUse").setDisabled();
		liger.get("rgnCityCdSecUse").setDisabled();
		liger.get("postAddr").setDisabled();
		liger.get("rgnProvCd").setDisabled();
		liger.get("rgnCityCd").setDisabled();
		liger.get("nation").setDisabled();
		liger.get("monthInc").setDisabled();
    }
}

function enableFields() {
	if (null != fromCAFlag && "true" == fromCAFlag) {
		liger.get("certValidEDt").setEnabled();
		liger.get("certValidEDtAll").setEnabled();
		$("#saveInsCfgDiv").show();
	}
	if (null != fromCMFlag && "true" == fromCMFlag) {
		liger.get("certValidEDt").setEnabled();
		liger.get("certValidEDtAll").setEnabled();
		$("#saveInsCfgDiv").show();
	}
}

/**
 * 校验时间格式
 */
function checkDateFormat(){
	var flag = 0;
	var params = {};
	params["certValidSDt"] = $("#certValidSDt").val();
	params["certValidEDt"] = $("#certValidEDt").val();
	$.ajax({
		type:'get',
		dataType:'json',
		async:false,
		url:'<%=path%>/customer/cstbscinfo/checkCertValid.do',
		data:params,
		success:function(data){
			//$.ligerDialog.SQalert({content: data.info,SQ_type: "success"});	
			if(data.success == 1){
				var oDate1 = new Date($("#certValidSDt").val());
		        var oDate2 = new Date($("#certValidEDt").val());
		        if(oDate1.getTime() < oDate2.getTime()){
					flag = 1;
		        }
		        else {
		        	UIUtils.alertError("证件有效起始日期 不能大于等于 证件有效终止日期");
		        }
			}else{
				UIUtils.alertError(data.info);
			}
		},
		error:function(data){
			UIUtils.alertError(data.info);
		}
	});
	return flag;
}

/**
 * 获取验证码
 */
function msmCode(){
	if($("#msmCodeCfg").attr("isSend") == '1'){
		return;
	}
	settime($("#msmCodeCfg"));
	var ligerForm = liger.get("ins_cfg_info_edit_form");

	var data = ligerForm.getData();
	if(!$("#bkCd").val()){
		top.$.ligerDialog.SQalert({content: "请选择开户银行！", SQ_type: "error"});
		return false;
	}

	if(!$("#accNo").val()){
		top.$.ligerDialog.SQalert({content: "请填写银行账号！", SQ_type: "error"});
		return false;
	}
	if(!$("#mp").val()){
		top.$.ligerDialog.SQalert({content: "请填写预留手机号码！", SQ_type: "error"});
		return false;
	}
	data["bkCd"] = liger.get("bkCd").selectedValue;
	data["bkNm"] = liger.get("bkCd").selectedText;
	data["accNo"] =  $("#accNo").val();
	data["mp"] = $("#mp").val();
	data["certNo"] = $("#certNo").val();
	data["prjId"] = $("#prjId").val();
	data["cstId"] = $("#cstId").val();
	data["cstNm"] = $("#cstNm").val();
	data["fundRasInsId"] = $("#fundRasInsId").val();
	var url = '<%=path%>/institution/xbfl/getVerificationCode.do';
	var wait_dialog;
	$.ajax({
		type: 'post',
		dataType: 'json',
		data: data,
		url: url,
		beforeSend: function () {
			wait_dialog = $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
		},
		success: function (msg) {
			wait_dialog.close();
			if (msg.success == 1) {
				if(msg.data && msg.data.rstCode && msg.data.rstCode == "393219"){
					isNeedPhoneCode = 2;
				}
				disabledInput();
				UIUtils.alertSuccessHold1(msg.info);
			} else {
				UIUtils.alertErrorHold1(msg.info);
			}
		}
	});
}
// 保存项目客户信息，后面弹出准入验证的资料确认页
function saveInfo() {
	var ligerForm = liger.get("ins_cfg_info_edit_form");
    if (!ligerForm.valid()) {
        top.$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO, SQ_type: "warning"});
        return false; //验证不通过，不执行以下代码
    }

	// 校验 身份证生效日 和 身份证到期日 数据格式
    // if(checkDateFormat() != 1){
    	// return ;
    // }
    var data = ligerForm.getData();
    if(!$("#bkCd").val()){
        top.$.ligerDialog.SQalert({content: "请选择开户银行！", SQ_type: "error"});
        return false;
    }

    if(!$("#accNo").val()){
        top.$.ligerDialog.SQalert({content: "请填写银行账号！", SQ_type: "error"});
        return false;
    }
    if(!$("#mp").val()){
        top.$.ligerDialog.SQalert({content: "请填写预留手机号码！", SQ_type: "error"});
        return false;
    }
	if(!$("#monthInc").val()){
		top.$.ligerDialog.SQalert({content: "请填写月收入！", SQ_type: "error"});
		return false;
	}
	if(!$("#nation").val()){
		top.$.ligerDialog.SQalert({content: "请选择民族！", SQ_type: "error"});
		return false;
	}
	if (!getRgnProvCdSecUse()) {
		top.$.ligerDialog.SQalert({content: "请填写居住地址-省!", SQ_type: "error"});
		return false;
	}
	if (!getRgnCityCdSecUse()) {
		top.$.ligerDialog.SQalert({content: "请填写居住地址-市!", SQ_type: "error"});
		return false;
	}
	if(!$("#postAddr").val()){
		top.$.ligerDialog.SQalert({content: "请填写居住地址详情！", SQ_type: "error"});
		return false;
	}
	if (!getRgnProvCd()) {
		top.$.ligerDialog.SQalert({content: "请填写户籍地址-省!", SQ_type: "error"});
		return false;
	}
	if (!getRgnCityCd()) {
		top.$.ligerDialog.SQalert({content: "请填写户籍地址-市!", SQ_type: "error"});
		return false;
	}

    data["bkCd"] = liger.get("bkCd").selectedValue;
    data["bkNm"] = liger.get("bkCd").selectedText;
    data["accNo"] =  $("#accNo").val();
    data["mp"] = $("#mp").val();
    data["certNo"] = $("#certNo").val();
    data["prjId"] = $("#prjId").val();
    data["cstId"] = $("#cstId").val();
    data["cstNm"] = $("#cstNm").val();
    data["fundRasInsId"] = $("#fundRasInsId").val();
    data["phoneCode"] = $("#phoneCode").val(); //
	data["certValidEDt"] = $("#certValidEDt").val();
	if($('#certValidEDtAll').is(':checked')){
		data["certValidEDt"] = "长期";
	}
	data["nation"] = $("#nation").val();
	data["monthInc"] = $("#monthInc").val();
	data["postProvince"] = getRgnProvCdSecUse();
	data["postCity"] = getRgnCityCdSecUse();
	data["postAddr"] = $("#postAddr").val();//居住地址详情
	data["domicileProvince"] = getRgnProvCd();//户籍地址-省
	data["domicleCity"] = getRgnCityCd();//户籍地址-市
    var url = '<%=path%>/institution/xbfl/save.do';
    var wait_dialog;
    $.ajax({
        type: 'post',
        dataType: 'json',
        data: data,
        url: url,
        beforeSend: function () {
            wait_dialog = $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
        },
        success: function (msg) {
            wait_dialog.close();
            if (msg.success == 1) {
            	disabledInput();
				UIUtils.alertSuccessHold1(msg.info);
            } else {
                UIUtils.alertErrorHold1(msg.info);
            }
        }
    });
}

var countdown = 60;

function settime(obj) { //发送验证码倒计时
	if (countdown == 0) {
		$(obj).removeClass("disabledBtn")
		$(obj).attr("style", "background: ");
		$(obj).attr("isSend", "0");
		$(obj).text("获取验证码");
		countdown = 60;
		return;
	} else {
		$(obj).addClass("disabledBtn")
		$(obj).attr("style", "background: gray;");
		$(obj).attr("isSend", "1");
		$(obj).text("重新发送(" + countdown + ")");
		countdown--;
	}
	setTimeout(function () {
		settime($(obj))
	}, 1000)
}

//选择长期置灰时间控件
function enduring(checkbox) {
	if ($("#certValidEDtAll").is(':checked')){
		$("#certValidEDt").hide();
		certValidEDt = "2099-12-31";
	} else {
		$("#certValidEDt").show();
		certValidEDt = null;
	}
}

function downloadFileByUrl() {
	var prjId = $("#prjId").val();
	var fundRasInsId = $("#fundRasInsId").val();
	var wait_dialog;
	$.ajax({
		type: 'post',
		dataType: 'json',
		data: {
			prjId: prjId,
			fundRasInsId: fundRasInsId
		},
		url: '<%=path%>/institution/xbfl/getPath.do',
		beforeSend: function () {
			wait_dialog = $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_LOADING, SQ_type: "waitting"});
		},
		success: function (msg) {
			wait_dialog.close();
			if (msg.success == 1 && msg.data != null) {
				//调用下载方法
				var actoinURL = '<%=path%>/institution/xbfl/zipDownloadByUrl.do?';
				var form = $("<form>");
				$('body').append(form);
				form.attr('style', 'display:none');
				form.attr('target', '');
				form.attr('method', 'post');
				form.attr('action', actoinURL);//下载文件的请求路径
				var input = $('<input>');
				input.attr('type', 'hidden');
				input.attr('name', 'urls');
				input.attr('value', msg.data);
				form.append(input);
				form.submit();
			} else {
				UIUtils.alertErrorHold1(msg.info);
			}
		}
	});
}
</script>

</body>
</html>